import {useUserInfoStore} from "@/stores/index.js";
import {checkLogin} from "@/utiles/route.js";

const userInfoStore = useUserInfoStore()

export function postLike(id,sign,post){
  if(!checkLogin())
    return;
  if (sign === 0) {
    post.likeCount = (post.likeCount || 0) + 1
    userInfoStore.addPostLike(id)
  } else if (sign === 1) {
    post.likeCount = (post.likeCount || 0) - 1
    userInfoStore.removePostLike(id)
  }
}

export function postCollect(id,sign,post){
  if(!checkLogin())
    return;
  if (sign === 0) {
    post.collectCount = (post.collectCount || 0) + 1
    userInfoStore.addPostCollect(id)
  } else if (sign === 1) {
    post.collectCount = (post.collectCount || 0) - 1
    userInfoStore.removePostCollect(id)
  }
}

export function follow(id,sign){
  if(!checkLogin())
    return;
  if(sign===0){
    userInfoStore.addFollow(id)
  }else if(sign===1){
    userInfoStore.removeFollow(id)
  }
}


